<?php 
	session_start();
	$forwardPage = "login.php";
	if(!isset($_SESSION['nit'])){
		header("Location: " . $forwardPage);
		exit();
	}
?>

<!DOCTYPE html>
<html lang="es">
    <head>
        <title>Reporte Ausentismo</title>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<link type="text/css" rel="stylesheet" href="css/TableTools.css" />
        <link type="text/css" rel="stylesheet" href="css/redmond/jquery-ui.css" />
        <link rel="shortcut icon" href="css/images/form.png" />
		<script src="js/jquery-1.8.3.js" type="text/javascript" ></script>
		<script src="js/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>
		<script src="js/jquery.dataTables.min.js" type="text/javascript"></script>
		<script src="js/ZeroClipboard.js" type="text/javascript"></script>
		<script src="js/TableTools.min.js" type="text/javascript"></script>
		<script type="text/javascript">
			$(document).ready(function(){
				var fechaInicial = <?php echo "'" . $_GET['fechaInicial'] . "'" ?>;
				var fechaFinal = <?php echo "'" . $_GET['fechaFinal'] . "'" ?>;
				$.ajax({
					dataType: "html",
					url: "exportar.php",
					data: {
						"fechaInicial": fechaInicial,
						"fechaFinal": fechaFinal
					},
					success: function(data) {
						var result = $.parseJSON(data);
						var l = result[0].length;
						var columns = [];
						for (var i = 0; i < l; i++){
							columns.push({"sTitle" : result[0][i]});
						}
						if (columns.length == 0){
							$('#resultadoExportar').append("<h2>No se obtuvieron resultados</h2>");
						}
						else
						{
							var oTable = $('#exportar').dataTable({
								"aaData": result[1],
								"aoColumns": columns,
								"bJQueryUI": true,
								"sPaginationType": "full_numbers",
								"bAutoWidth": true,
								"sScrollX": "100%",
								"bScrollCollapse": true,
								"oLanguage": {
									"sProcessing":     "Procesando...",
									"sLengthMenu":     "Mostrar _MENU_ registros",
									"sZeroRecords":    "No se encontraron resultados",
									"sEmptyTable":     "Ning&uacute;n dato disponible en esta tabla",
									"sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
									"sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
									"sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
									"sInfoPostFix":    "",
									"sSearch":         "Buscar:",
									"sUrl":            "",
									"sInfoThousands":  ",",
									"sLoadingRecords": "Cargando...",
									"oPaginate": {
										"sFirst":    "Primero",
										"sLast":     "&Uacute;ltimo",
										"sNext":     "Siguiente",
										"sPrevious": "Anterior"
									},
									"fnInfoCallback": null,
									"oAria": {
										"sSortAscending":  ": Activar para ordernar la columna de manera ascendente",
										"sSortDescending": ": Activar para ordernar la columna de manera descendente"
									}
								},
								"sDom": 'T<"H"f>t<"F"ilrp>',
								"oTableTools": {
									"aButtons": [
										{
											"sExtends":    "copy",
											"sButtonText": "Copiar"
										},
										{
											"sExtends":    "collection",
											"sButtonText": "Guardar",
											"aButtons":    [
												{
													"sExtends":    "xls",
													"sButtonText": "Excel",
													"bHeader": true,
													"sToolTip": "Guardar como archivo de Excel (csv)"
												}
											]
										}
									]
								}
							});
							oTable.$('td').hover( function() {
								var iCol = $('td', this.parentNode).index(this);
								$('td:nth-child('+(iCol+1)+')', oTable.$('tr')).addClass( 'highlighted' );
							}, function() {
								oTable.$('td.highlighted').removeClass('highlighted');
							} );
						}
					}
				});
			});
		</script>
		<style type="text/css">
			.highlighted, #exportar tbody tr.even:hover td, #exportar tbody tr.odd:hover td{
				background-color: #DEEDF7 !important;
			}

			#exportar  {
				
			}

			#exportar tbody tr td {
				border:1px #87B6D9 solid;
				text-align: center;
			}

			div.DTTT_container {
				margin-top: 7px;
				margin-bottom: 7px;
				margin-right: 15px
			} 
			 
			.dataTables_processing {
				position: absolute;
				top: 0px;
				left: 50%;
				width: 250px;
				margin-left: -125px;
				border: 1px solid #ddd;
				text-align: center;
				color: #999;
				font-size: 11px;
				padding: 2px 0;
			}

			.dataTables_length {
				text-align:center;
				float: left;
				margin: 3px auto;
			}

			.dataTables_filter {
				width: auto;
				float: left;
				margin-top: 7px;
				margin-bottom: 7px;
				margin-left: 15px;
			}

			.dataTables_info {
				width: 40%;
				float: left;
				margin-top: 3px;
				margin-bottom: 3px;
				margin-left: 15px;
			}

			.dataTables_paginate {
				width: 40%;
				float: right;
				text-align: right;
				margin-top: 3px;
				margin-bottom: 3px;
				margin-right: 15px;
			}

			.dataTables_paginate a {
				width: auto;
				clear: left;
				margin-top: 3px;
				margin-bottom: 3px;
				margin-right: 0 !important;
				padding: 0 3px;
			}
			div#atrasDIV {
				text-align: center;
				margin: 10px auto;
			}

			a#atras {
				margin: 10px auto;
			}
		</style>
    </head>
    <body>
		<div id="resultadoExportar">
		    	<table id="exportar">
		    		<thead></thead>
		    		<tbody></tbody>
		    	</table>
		</div>
		<div id="atrasDIV">
			<a id="atras" href='javascript: history.back()'>Volver al Formulario</a>
		</div>
    </body>
</html>
